﻿using BLL;
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS._6.ZhangWuGL
{
    public partial class DuoShouZZ_CK : BasePage
    {
        #region 属性
        private DataTable dtZhuanChuXX
        {
            get
            {
                return ViewState["_dtDuoShouXX"] as DataTable;
            }
            set
            {
                ViewState["_dtDuoShouXX"] = value;
            }
        }
        #endregion
        #region 变量
        /// <summary>
        /// 系统参数操作类
        /// </summary>
        private S_SETTINGSBLL _S_SETTINGBLL = new S_SETTINGSBLL();
        /// <summary>
        /// 系统参数实体
        /// </summary>
        private S_SETTINGS _S_SETTINGS;
        /// <summary>
        /// 数据访问操作类
        /// </summary>
        private SpHelper _spHelper = new SpHelper();
        #endregion
        #region 私有方法
        private void InitData()
        {
            _S_SETTINGS = _S_SETTINGBLL.GetCurrentZhangWuNY();
            this.txtZhangWuNY.Text = _S_SETTINGS.CONFIGVALUE;
            GetDuoShouZZSJ();
        }
        /// <summary>
        /// 获取多收转账数据
        /// </summary>
        private void GetDuoShouZZSJ()
        {
            int _ZhangWuNY = Convert.ToInt32(this.txtZhangWuNY.Text.Trim());
            DataTable dt = _spHelper.P_QS_ZW_GETDUOSHOUZZSJ(_ZhangWuNY).Tables[0];
            this.dtZhuanChuXX = dt;
            this.gvMingXi.DataSource = this.dtZhuanChuXX;
            this.gvMingXi.DataBind();
            decimal _amount = 0;
            foreach (DataRow dr in dt.Rows)
            {
                _amount += Convert.ToDecimal(dr["N_JINE"]);
            }
            this.txtZongBiS.Text = dt.Rows.Count.ToString();
            this.txtZongJinE.Text = string.Format("{0:N2}", _amount);
        }

        private string CheckDataValid()
        {
            string _ErrMsg = "";
            string _ZhangWuNY = this.txtZhangWuNY.Text.Trim();
            if (string.IsNullOrEmpty(_ZhangWuNY))
            {
                _ErrMsg = "请输入正确的账务年月";
                return _ErrMsg;
            }
            if (_ZhangWuNY.Length != 6)
            {
                _ErrMsg = "请输入正确的账务年月";
                return _ErrMsg;
            }
            if (!PageTools.ValidateString(_ZhangWuNY, PageTools.eValidateType.数字))
            {
                _ErrMsg = "请输入正确的账务年月";
                return _ErrMsg;
            }
            return _ErrMsg;
        }
        #endregion
        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string _ErrMsg = CheckDataValid();
            if (!string.IsNullOrEmpty(_ErrMsg))
            {
                PageTools.AlertMsg(this, _ErrMsg);
                return;
            }
            GetDuoShouZZSJ();
        }
        #endregion
    }
}